--
module("UI.Windows.LiuShuiJiLuWin", package.seeall)

local UIUtility = require("UI.Utility")
local UIWindow = require("UI.UIWindow").UIWindow
local UIWinMgr = require("UI.UIWinMgr").UIWinMgr
local json = require("cjson")
LiuShuiJiLuWin = UIWindow:new()

LiuShuiJiLuWin.name = "LiuShuiJiLuWin"

local GameObject = UnityEngine.GameObject


function LiuShuiJiLuWin:Init()
    local t = self.Container.transform

    self.close_btn = UIUtility.GetChildTransform("close_btn", t, true)
    self:BindEvents()

    self.grid_item=UIUtility.GetChildTransform("grid_item", t, true)
    self.panel_grid=UIUtility.FindContorl("UIGrid", "panel_grid", t)
    
 
end

function LiuShuiJiLuWin:OnShow()

    local allGameList_data=require("UI.Windows.NewGameLoobyWin").NewGameLoobyWin.allGameList_data
    --获取流水记录
    require("NetWork.NetHttp").SendGetRequest("/game/game/bet/order/page?pageNum=1&pageSize=10",function(ok,data)
        if ok then
            -- ["platformBetId"] = "06E250604112940N847F",
            -- ["gameType"] = 3,
            -- ["gamePlatformId"] = 3,
            -- ["betAmount"] = 1300,
            -- ["gameName"] = userdata<userdata: NULL>,
            -- ["platformOrderId"] = "1130215-1116",
            -- ["betOrderId"] = 278,
            -- ["gameIndex"] = "6",
            -- ["userId"] = 102355,
            -- ["gamePlatformName"] = "WL",
            -- ["settleTime"] = "2025-06-04 11:29:40",
            -- ["isCount"] = 0,
            -- ["totalBetAmount"] = 1300,
            -- ["state"] = 1,
            -- ["username"] = "cy1996",
            -- ["winAmount"] = -1300,
            -- ["betTime"] = "2025-06-04 11:28:38",
            for i = 1, self.panel_grid.transform.childCount do
                if i ~= 1 then
                    GameObject.Destroy(self.panel_grid.transform:GetChild(i - 1).gameObject)
                end
            end
            for i = 1, #data.data.records do
                local item = GameObject.Instantiate(self.grid_item)
                item.gameObject:SetActive(true)
                item.transform.parent = self.panel_grid.transform
                item.transform.localScale = Vector3.one
                item.transform.localPosition = Vector3.zero
                item.transform.localEulerAngles = Vector3.zero

                for j = 1, #allGameList_data do
                    if allGameList_data[j].gamePlatformId == data.data.records[i].gamePlatformId and allGameList_data[j].gameIndex == data.data.records[i].gameIndex then
                        
                        UIUtility.FindContorl("UILabel", "name", item).text =allGameList_data[j].gameName 
                        break
                    end
                    UIUtility.FindContorl("UILabel", "name", item).text = data.data.records[i].gamePlatformName 
                end

                UIUtility.GetChildTransform("bg", item, true).gameObject:SetActive(i%2~=0)

                UIUtility.FindContorl("UILabel", "time", item).text = data.data.records[i].settleTime
                UIUtility.FindContorl("UILabel", "type", item).text = data.data.records[i].gamePlatformName
              
                UIUtility.FindContorl("UILabel", "num", item).text = data.data.records[i].winAmount/100  
                if data.data.records[i].winAmount >= 0 then
                    UIUtility.FindContorl("UILabel", "num", item).color=Color(35/255,183/255,20/255)
                else
                    UIUtility.FindContorl("UILabel", "num", item).color=Color(205/255,91/255,70/255)
                end
            end
            self.panel_grid.repositionNow = true
            self.panel_grid:Reposition()
            
            print("获取流水记录" .. stringify(data))
        else
            print("获取流水记录失败" .. stringify(data))
        end
    end)

end

function LiuShuiJiLuWin:OnClose()

end

function LiuShuiJiLuWin:BindEvents()
    UIHelper.BindUIEvnet("Click", function()
        self:Close(1)
    end, self.close_btn.gameObject)
end
